<template>
  <!-- 会员管理 -->
  <view class="shopassistant-content">
    <view class="shopassistant-item flex justify-between items-center mb-24" v-for="(item, index) in collectionList"
      :key="index" @click="onGoodsClick(item)">
      <view>
        <view class="tit mb-20">
          <text>{{ item.name }}</text>
          <text class="ml-8">{{ item.mobile }}</text>
        </view>
        <view class="subtit">
          余额:{{ item.balance }}
        </view>
      </view>
      <view>
        <image class="chevronright" :src="IMG_URL2+'common/chevron-right.svg'"></image>
      </view>
    </view>
    <up-divider v-if="collectionList.length>pageSize"  :text="loadStatus"></up-divider>
    <view class="button-box px-48">
      <view class="exit-login bg2" @click="AddClerk">添加会员</view>
    </view>
  </view>
</template>

<script setup>
import { shopApi } from "@/api";
import { IMG_URL2 } from "@/config";
let currentPage = ref(1)
let pageSize = ref(15)
let totalCount = ref(0)
let loadStatus = ref('正在加载中')
const collectionList = ref([]);
function getShopStaffList(type) {
  let params = {
    "currentPage": currentPage.value,
    "pageSize": pageSize.value
  }
  shopApi.SHOPGETMEMBERLIST(params).then((res) => {
    if (res.code == 200) {
      if (type == 1) {
        collectionList.value = res.result.data
        totalCount.value = res.result.totalCount
      } else {
        collectionList.value = collectionList.value.concat(res.result.data)
      }
    }else{
      uni.showToast({
          title: res.errMsg,
          icon: "success",
      });
  }
  });
}
function RoleValue(val) {
  if (val) {
    return RoleData.find(item => item.value == val).label
  }

}
onShow(() => {
  getShopStaffList(1)
});


// 触底加载
onReachBottom(() => {
  console.log("触底加载");
  if (collectionList.value.length >= totalCount.value) {
    loadStatus.value = "没有更多数据了";
    return
  }
  loadStatus.value = "正在加载中";
  currentPage.value++
  getShopStaffList(2)
});

// 下拉刷新
onPullDownRefresh(() => {
  uni.showToast({
    title: "下拉刷新",
    icon: "none",
    duration: 1000
  });
  loadStatus.value = "正在加载中";
  currentPage.value = 1
  totalCount.value = 0
  isloading.value = false
  collectionList.value = [];
  getShopStaffList(1)
  setTimeout(() => {
    uni.stopPullDownRefresh();
  }, 2000);
});

const onGoodsClick = (item) => {
  uni.navigateTo({
    url: `/pagesshop/member/details?id=${item.userId}`
  });
};


const AddClerk = () => {
  uni.navigateTo({
    url: `/pagesshop/member/info`
  });
};

</script>

<style lang="scss">
page {
  background-color: #f3f3f3;
}
</style>
<style lang="scss" scoped>
.shopassistant-content {
  position: relative;

  .shopassistant-item {
    padding: 20px;
    box-sizing: border-box;
    background-color: #fff;
    margin-top: 24rpx;

    .tit {
      font-family: PingFang SC;
      font-size: 14px;
      font-weight: 400;
      text-align: left;
      color: rgba(0, 0, 0, 0.9);
    }

    .subtit {
      font-family: PingFang SC;
      font-size: 14px;
      text-align: left;
      color: rgba(0, 0, 0, 0.6);

    }

    .chevronright {
      width: 16px;
      height: 16px;

    }
  }

  .button-box {
    width: 100%;
    position: fixed;
    bottom: 0rpx;
    left: 0;
    z-index: 9;
    background-color: #fff;
  }

  .exit-login {
    width: 654rpx;
    height: 92rpx;
    line-height: 92rpx;
    background: #D68E44;
    color: #ffffff;
    text-align: center;
    border-radius: 64px;
    font-size: 32rpx;
    margin-bottom: 40rpx;
  }

  .bg1 {
    background: rgba(253, 236, 219, 1);
    color: rgba(145, 74, 0, 1);
  }

  .exit-login:after {
    border: none;
  }
}
</style>